<template>
  <div class="chat-container">
    <header>
      <h1>AI聊天</h1>
    </header>
    <main class="chat-messages">
      <div v-if="messages.length === 0" class="no-message">
        <p>还没有开始聊天</p>
        <p>请在下方输入消息</p>
      </div>
      <div v-else>
        <div v-for="msg in messages" :key="msg.id" :class="{ 'user-message': msg.type === 'user', 'ai-message': msg.type === 'ai' }">
          <p>{{ msg.content }}</p>
        </div>
      </div>
    </main>
    <footer class="chat-input">
      <input type="text" v-model="inputMessage" @keyup.enter="sendMessage" placeholder="请输入消息...">
      <button @click="sendMessage">发送</button>
    </footer>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  name: 'AIChat',
  setup() {
    const messages = ref([])
    const inputMessage = ref('')

    const sendMessage = () => {
      if (inputMessage.value.trim() === '') return

      // 添加用户消息
      messages.value.push({
        id: Date.now(),
        type: 'user',
        content: inputMessage.value
      })

      // 清空输入框
      inputMessage.value = ''

      // 模拟AI回复
      setTimeout(() => {
        messages.value.push({
          id: Date.now() + 1,
          type: 'ai',
          content: '这是AI的回复。在实际项目中，这里会调用DeepSeekR1的API获取真实回复。'
        })
      }, 1000)
    }

    return {
      messages,
      inputMessage,
      sendMessage
    }
  }
}
</script>

<style scoped>
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  padding: 10px 20px;
  background-color: #42b983;
  color: white;
  text-align: center;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background-color: #f9f9f9;
}

.no-message {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: #999;
}

.user-message,
.ai-message {
  max-width: 80%;
  margin-bottom: 15px;
  padding: 10px 15px;
  border-radius: 8px;
  word-break: break-word;
}

.user-message {
  margin-left: auto;
  background-color: #42b983;
  color: white;
}

.ai-message {
  margin-right: auto;
  background-color: #fff;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

.chat-input {
  display: flex;
  padding: 10px;
  background-color: #fff;
  border-top: 1px solid #ddd;
}

.chat-input input {
  flex: 1;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
  outline: none;
}

.chat-input button {
  padding: 10px 20px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.chat-input button:hover {
  background-color: #3aa876;
}
</style>